package com.xuerhua.yxt.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xuerhua.yxt.dao.AttachmentListMapper;
import com.xuerhua.yxt.dao.PrincipalMailboxMapper;
import com.xuerhua.yxt.model.PrincipalMailbox;
import com.xuerhua.yxt.page.Page;
import com.xuerhua.yxt.reqVo.AttachRelationReqVO;
import com.xuerhua.yxt.reqVo.MailboxReqVO;
import com.xuerhua.yxt.service.IPrincipalMailboxService;
import com.xuerhua.yxt.view.PrincipalMailboxView;

@Service("principalMailboxService")
public class PrincipalMailboxServiceImpl implements IPrincipalMailboxService {

	@Autowired
	private PrincipalMailboxMapper principalMailboxMapper;
	@Autowired
	private AttachmentListMapper attachmentListMapper;
	
	@Override
	public int insert(MailboxReqVO record) {
		principalMailboxMapper.insertSelective(record);
		if(record.getIsAttach() != null) {
			AttachRelationReqVO attach = new AttachRelationReqVO();
			attach.setRelationId(Long.valueOf(record.getId()));
			attach.setAttachIds(record.getIds());
			attach.setSchoolId(record.getSchoolId());
			return attachmentListMapper.updateRelationIdByIds(attach);
		}
		return 1;
	}

	@Override
	public PrincipalMailbox selectByPrimaryKey(Integer id) {
		return principalMailboxMapper.selectByPrimaryKey(id);
	}

	@Override
	public int updateByPrimaryKeySelective(PrincipalMailbox record) {
		return principalMailboxMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public List<PrincipalMailboxView> selectListByPage(Page<PrincipalMailboxView> page) {
		return principalMailboxMapper.selectListByPage(page);
	}

}
